package cpgears.views {
	import asunit.framework.TestCase;
	import cpgears.movie.CPMovieAdapter;
	import cpgears.movie.MovieMock;
	import cpgears.properties.WidgetPropertiesBase;
	import cpgears.views.manager.SimpleViewManager;
	import cpgears.WidgetBase;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author Whyves
	 */
	public class SimpleViewManagerTest extends TestCase{
		
		private var mContainer:DisplayObjectContainer = null;
		private var mViewManager:SimpleViewManager = null;
		private var mProperties:WidgetPropertiesBase = null;
		
		public function SimpleViewManagerTest(testMethod:String = null) {
			super(testMethod);
		}
		
		override protected function setUp():void {
			mContainer = new MovieClip();
			mViewManager = new SimpleViewManager(new DummyView("edit"), new DummyRuntimeView("runtime"), new DummyView("stage"), new DummyView("preview"));
			mViewManager.rootContainer = mContainer;
			mProperties = new WidgetPropertiesBase(prototype);
		}
		
		public function testNoViewVisibleByDefault():void {
			assertEquals("No view should be visible after instanciation", 0, mContainer.numChildren);
		}
		
		public function testShowEditView():void {
			mViewManager.showEditView(mProperties);
			var view:DummyView = mContainer.getChildAt(0) as DummyView;
			assertEquals("The 'edit' view should be visible", "edit", view.viewName);
		}
		
		public function testShowRuntimeView():void {
			mViewManager.showRuntimeView(mProperties, new CPMovieAdapter(new MovieMock(), new WidgetBase()));
			var view:DummyRuntimeView = mContainer.getChildAt(0) as DummyRuntimeView;
			assertEquals("The 'runtime' view should be visible", "runtime", view.viewName);
		}

		public function testShowStageView():void {
			mViewManager.showStageView(mProperties);
			var view:DummyView = mContainer.getChildAt(0) as DummyView;
			assertEquals("The 'stage' view should be visible", "stage", view.viewName);
		}

		public function testshowPreview():void {
			mViewManager.showPreview(mProperties);
			var view:DummyView = mContainer.getChildAt(0) as DummyView;
			assertEquals("The 'preview' view should be visible", "preview", view.viewName);
		}
		
		public function testOneViewAtATime():void {
			mViewManager.showEditView(mProperties);
			mViewManager.showPreview(mProperties);
			mViewManager.showRuntimeView(mProperties, new CPMovieAdapter(new MovieMock(), new WidgetBase()));
			mViewManager.showStageView(mProperties);
			assertEquals("There should only be one view at a time", 1, mContainer.numChildren);
		}
		
		public function testNullRootContainer():void {
			mViewManager.showEditView(mProperties);
			assertEquals("There should be one view displayed", 1, mContainer.numChildren);
			mViewManager.rootContainer = null;
			assertEquals("There should be no view displayed", 0, mContainer.numChildren);
		}
	}

}